package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.utils.AutoFill;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @PostMapping
    @ApiOperation("新增")
    public Result<PageResult> save(@RequestBody SetmealDTO setmealDTO){
        setmealService.save(setmealDTO);
        return Result.success();
    }
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult = setmealService.page(setmealPageQueryDTO);
        return Result.success(pageResult);
    }
    @ApiOperation("修改")
    @PutMapping
    public Result<PageResult> update(@RequestBody SetmealDTO setmealDTO){
        setmealService.update(setmealDTO);
        return Result.success();
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查菜品")
    public Result<SetmealVO> save(@PathVariable Long id){
        log.info("根据id查菜品：{}", id);
        SetmealVO setmealVO=setmealService.queryById(id);
        return Result.success(setmealVO);
    }
    @DeleteMapping
    @ApiOperation("批量删除套餐")
    public Result delete(@RequestParam ArrayList<Long> ids){
        log.info("批量删除菜品：{}", ids);
        setmealService.delete(ids);

        return Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation("套餐启售/停售")
    public Result setStatus(@PathVariable Integer status,@RequestParam Long id){
        log.info("菜品启售/停售：{}", status);
        setmealService.setStatus(status,id);

        return Result.success();
    }
}
